Type.registerNamespace('ModWatch');

ModWatch.OnCheckBoxChangedModAlertBehavior = function(element) { 
    ModWatch.OnCheckBoxChangedModAlertBehavior.initializeBase(this, [element]);

    this._isSelected = false;
	this._previousOnClickEvent = null;
}

ModWatch.OnCheckBoxChangedModAlertBehavior.prototype =
{

	_onClick : function(e)
	{
		if (!ModWatch.OnCheckBoxChangedModAlertBehavior.callBaseMethod(this, 'verifyChanges'))
		{
			// roll back the change
			this.get_element().checked = this._isSelected;
			return false;
		}
		else
		{
			// store the new selected index
			this._isSelected = this.get_element().checked;

			if (this._previousOnClickEvent != null)
			{
				return this._previousOnClickEvent(e);
			}
		}
	},

	initialize : function()
	{
		ModWatch.OnCheckBoxChangedModAlertBehavior.callBaseMethod(this, 'initialize');

		var cb = this.get_element();
		var currentChangeEvent = cb.onclick;
		if (typeof currentChangeEvent == 'function')
		{
			this._previousOnClickEvent = currentChangeEvent;
		}

		this._isSelected = cb.checked;

		$addHandlers(cb, 
					 { 'click' : this._onClick },
					 this);

		cb.onclick = null;
	},

	dispose : function()
	{
		this.get_element().onclick = this._previousOnClickEvent;

		$clearHandlers(this.get_element());

		ModWatch.OnCheckBoxChangedModAlertBehavior.callBaseMethod(this, 'dispose');
	}

}

ModWatch.OnCheckBoxChangedModAlertBehavior.registerClass('ModWatch.OnCheckBoxChangedModAlertBehavior', ModWatch.ModAlertBehaviorBase);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
